#!/bin/bash
declare -A config
declare -A sshconfig
declare -A mysqlconfig
mysqlconfig=(['host']='xxx.xxx.xxx.xxx' [port]='3306' [user]='dbuser' \
    [pass]='dbpwd')
sshconfig=(['host']='xxx.xxx.xxx.xxx' [port]='22' \
    [user]='sshUser' [pass]='sshpwd')
localport='3307'
connect=0
#mysql -uroot -p

# make tunnel
#sshpass -p"${sshconfig[pass]}" ssh -f ${sshconfig[user]}@${sshconfig[host]} \
ssh -f ${sshconfig[user]}@${sshconfig[host]} \
    -o StrictHostKeyChecking=no \
    -L ${localport}:${mysqlconfig[host]}:${mysqlconfig[port]} \
    -N -p ${sshconfig[port]} 


echo $?
if [ $? -eq 0  -a "${connect}" -eq "1" ];then
    mysql -h 127.0.0.1 -u ${mysqlconfig[user]} -P ${localport}\
    -p"${mysqlconfig[pass]}"
fi
